#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);


}

MainWindow::~MainWindow()
{
    tcpsock->close();
    delete ui;
}

void MainWindow::read(){
        QString newData = tcpsock->readAll();
        QString allData = "服务器："  + newData;
        ui->plainTextEdit->appendPlainText(allData);
}


void MainWindow::on_pushButton_2_clicked()
{
    tcpsock = new QTcpSocket();
//    tcpsock->bind(QHostAddress("192.168.6.72"),8889);
    tcpsock->connectToHost(ui->lineEdit->text(),ui->lineEdit_2->text().toInt());

    connect(tcpsock, SIGNAL(readyRead()), this, SLOT(read()));
}

void MainWindow::on_pushButton_clicked()
{
    tcpsock->write(ui->textEdit->toPlainText().toUtf8());
    QString allData = "我："  + ui->textEdit->toPlainText().toUtf8();
    ui->plainTextEdit->appendPlainText(allData);
    ui->textEdit->setPlainText("");
}
